package com.jp.knowledge.my.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.my.adapter.MyFranchiseAdapter;
import com.jp.knowledge.my.business.MyVipBusiness;
import com.jp.knowledge.my.model.ActiveDataModel;
import com.jp.knowledge.view.RecycleViewDiver;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 公司特权
 *
 * @author gzejia 978862664@qq.com
 */
public class OrganizeFranchiseActivity extends SlidingActivity {

    @ViewInject(R.id.organize_franchise_rv)
    private RecyclerView mOrganizeFranchiseRv;

    @ViewInject(R.id.organize_franchise_tv_grad)
    private TextView mGradTv;

    @ViewInject(R.id.organize_franchise_tv_integration)
    private TextView mIntegrationTv;

    @ViewInject(R.id.organize_franchise_tv_attestation)
    private View mAttestationLly;

    @ViewInject(R.id.organize_franchise_tv_upgrade)
    private View mUpgradeLly;

    private MyVipBusiness mBusiness = new MyVipBusiness();

    @Override
    protected int getResourceId() {
        return R.layout.activity_organize_franchise;
    }

    @Override
    protected void init() {
        initTitle();
        initOthers();
        initOrganizeFranchiseRv(mBusiness.getFranchiseOrganizeData(getFranchiseIndex(
                MyVipBusiness.FRANCHISE_ORGANIZE_SIZE)));
    }

    @Event(value = {R.id.icon_left, R.id.organize_franchise_tv_attestation,
            R.id.organize_franchise_tv_upgrade}, type = View.OnClickListener.class)
    private void onClick(View view) {
        switch (view.getId()) {
            case R.id.organize_franchise_tv_attestation:// 我要认证
                break;
            case R.id.organize_franchise_tv_upgrade:// 公司特权处理
                break;
            case R.id.icon_left:// 返回
                finish();
                break;
        }
    }

    private void initTitle() {
        topName.setText(R.string.my_tv_franchise_organize);
        topDesc.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        rightIcon.setVisibility(View.GONE);
    }

    private void initOrganizeFranchiseRv(List<ActiveDataModel> list) {
        mOrganizeFranchiseRv.setHasFixedSize(true);
        mOrganizeFranchiseRv.addItemDecoration(new RecycleViewDiver(this, LinearLayout.VERTICAL));
        mOrganizeFranchiseRv.setLayoutManager(new GridLayoutManager(this, 4));
        MyFranchiseAdapter mFranchiseAdapter = new MyFranchiseAdapter(this, list);
        mOrganizeFranchiseRv.setAdapter(mFranchiseAdapter);
    }

    private void initOthers() {
        int mOrganizeStat = 0;// 假定公司认证状态

        switch (mOrganizeStat) {
            case 0:// 未认证
                mAttestationLly.setVisibility(View.VISIBLE);
                mUpgradeLly.setVisibility(View.VISIBLE);
                break;
            case 1:// 已认证未升级特权
                mAttestationLly.setVisibility(View.GONE);
                mUpgradeLly.setVisibility(View.VISIBLE);
                break;
            case 2:// 已认证并升级特权
                mAttestationLly.setVisibility(View.GONE);
                mUpgradeLly.setVisibility(View.GONE);
                break;
        }

        mGradTv.setText("未认证公司");
        mIntegrationTv.setText(String.valueOf(235));
    }

    /**
     * @return 假定特权数据量
     */
    private List<Integer> getFranchiseIndex(int maxSize) {
        List<Integer> index = new ArrayList<>();
        for (int i = 0; i < maxSize; i++) {
            index.add((int) (Math.random() * 399) - 199);
        }
        return index;
    }
}
